package com.fwtai.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.datasource.DaoHandle;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * 产品（商品）访问数据库
 * @作者 田应平
 * @版本 v1.0
 * @创建时间 2023-10-31 15:22:53
 * @QQ号码 444141300
 * @Email service@fwtai.com
 * @官网 <url>http://www.fwtai.com</url>
*/
@Repository
public class MallGoodsDao{

  private final DaoHandle dao;

  public MallGoodsDao(final DaoHandle dao){
    this.dao = dao;
  }

  @Transactional
  public int add(final PageFormData formData){
    dao.execute("mall_goods.add_spec",formData);
    return dao.execute("mall_goods.add",formData);
  }

  public int edit(final PageFormData formData){
    return dao.execute("mall_goods.edit",formData);
  }

  public Long queryExistById(final long kid){
    return dao.queryForLong("mall_goods.queryExistById",kid);
  }

  public HashMap<String,Object> queryById(final long kid){
    return dao.queryForHashMap("mall_goods.queryById",kid);
  }

  public List<HashMap<String,String>> queryFiles(final long[] lists){
    return dao.queryForListString("mall_goods.queryFiles",lists);
  }

  @Transactional
  public int delByKeys(final long[] list){
    dao.execute("mall_goods.delRoles",list);
    return dao.execute("mall_goods.delByKeys",list);
  }

  public int editValid(final PageFormData formData){
    return dao.execute("mall_goods.editValid",formData);
  }

  public List<HashMap<String,Object>> getGoodsSpecList(final PageFormData formData){
    return dao.queryForListHashMap("mall_goods.getGoodsSpecList",formData);
  }

  public Integer getGoodsSpecTotal(final PageFormData formData){
    return dao.queryForInteger("mall_goods.getGoodsSpecTotal",formData);
  }

  public List<HashMap<String,Object>> getListData(final PageFormData formData){
    return dao.queryForListHashMap("mall_goods.listData",formData);
  }

  public Integer getListTotal(final PageFormData formData){
    return dao.queryForInteger("mall_goods.listTotal",formData);
  }

  //获取表goods的字段category的下拉框列动态值选项的数据
  public List<HashMap<String,Object>> getCategory(){
    return dao.queryForListHashMap("mall_goods.getCategory");
  }

  public HashMap<String,Object> querySpecInfo(final long kid){
    return dao.queryForHashMap("mall_goods.querySpecInfo",kid);
  }

  public int addGoodSpec(final PageFormData formData){
    return dao.execute("mall_goods.add_spec",formData);
  }

  public HashMap<String,String> queryExistSpecById(final long kid){
    return dao.queryForHashMapString("mall_goods.queryExistSpecById",kid);
  }

  public int editGoodSpec(final PageFormData formData){
    return dao.execute("mall_goods.editGoodSpec",formData);
  }

  public int editSpecStatus(final PageFormData formData){
    return dao.execute("mall_goods.editSpecStatus",formData);
  }
}